package org.team751.util;


/**
 * Smooths many input values
 * @author Programmer
 */
public class ValueSmoother {
    private double[] values;

    public ValueSmoother(int numValues){
        values = new double[numValues];
    }

    public void addValue(double value){
        //Shift everything one index up
        //(length-2) => (length-1) and so on all the way to 0 => 1
        for(int i = values.length - 2; i >= 0; i--){
            values[i+1] = values[i];
        }
        //Add to index 0
        values[0] = value;
    }

    public double getAverage(){
        double total = 0;
        //get the total of all the values
        for(int i = 0; i < values.length; i++){
            total += values[i];
        }
        //divide it by the total number of samples to get the average
        double average = total / (double)values.length;
        return average;
    }
}
